import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import tableRouter from './modules/table'

/**
*注意：子菜单仅在路由子项时显示。长度>=1
*详情见：https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
*隐藏：true如果设置为true，项目将不会显示在侧栏中（默认值为false）
*alwaysShow:true如果设置为true，将始终显示根菜单
*如果未设置alwaysShow，则当项目有多个子路线时，
*它将变为嵌套模式，否则不显示根菜单
*重定向：如果设置为noRedirect，noRedirect将不会在面包屑中重定向
*名称：'router-name'该名称由<keep-alive>使用（必须设置！！！）
*元：{
角色：['admin'，'enterprise']控制页面角色（您可以设置多个角色）
标题：“标题”侧边栏和面包屑中显示的名称（推荐设置）
图标：“svg名称”/“el-icon-x”侧边栏中显示的图标
noCache:true如果设置为true，则不会缓存页面（默认值为false）
粘贴：true如果设置为true，则标签将粘贴在“标签”视图中
breadcrumb:false如果设置为false，则项目将隐藏在breadcrumb中（默认为true）
activeMenu:“/example/list”如果设置路径，侧边栏将突出显示您设置的路径
}
*/
/**
* constantRoutes
*没有权限要求的基页
*可以访问所有角色
*/

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },


  // 用户前台
  {
    path: '/home',
    component: () => import('@/views/home/home'),
    hidden: true
  },
  // 职位列表
  {
    path: '/positionList',
    component: () => import('@/views/position/positionList'),
    hidden: true
  },
  // 职位详情
  {
    path: '/positionDetail',
    component: () => import('@/views/position/positionDetail'),
    hidden: true
  },
  // 人才列表
  {
    path: '/personnelList',
    component: () => import('@/views/personnel/personnelList'),
    hidden: true
  },
  // 企业列表
  {
    path: '/enterpriseList',
    component: () => import('@/views/enterprise/enterpriseList'),
    hidden: true
  },
  // 企业详情
  {
    path: '/enterpriseDetail',
    component: () => import('@/views/enterprise/enterpriseDetail'),
    hidden: true,
  },
  // 校园招聘
  {
    path: '/campusRecruitment',
    component: () => import('@/views/home/campusRecruitment'),
    hidden: true
  },
  // 视频会议
  {
    path: '/videoconferencing',
    component: () => import('@/views/home/videoconferencing'),
    hidden: true
  },
  // 招聘会
  {
    path: '/jobFair',
    component: () => import('@/views/home/jobFair'),
    hidden: true
  },
  // 职场资讯
  {
    path: '/workplaceInfo',
    component: () => import('@/views/home/workplaceInfo'),
    hidden: true
  },



  // 后台管理系统路由
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
*异步路由
*需要根据用户角色动态加载的路由
*/
export const asyncRoutes = [
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, //将始终显示根菜单
    name: 'Permission',
    meta: {
      title: 'permission',
      icon: 'lock',
      roles: ['admin', 'enterprise'] //您可以在根导航中设置角色
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'pagePermission',
          roles: ['admin'] //或者只能在子导航中设置角色
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'directivePermission'
          //如果不设置角色，则表示：此页面不需要权限
        }
      },
      {
        path: 'role',
        component: () => import('@/views/permission/role'),
        name: 'RolePermission',
        meta: {
          title: 'rolePermission',
          roles: ['admin']
        }
      }
    ]
  },

  //简历编辑
  {
    path: '/resume',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/resume/resumeEdit',
        name: 'ResumeEdit',
        component: () => import('@/views/resume/resumeEdit'),
        meta: {
          title: 'resumeEdit',
        }
      }
    ]
  },
  // 简历详情
  {
    path: '/resume',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/resume/resumeDetails',
        name: 'ResumeDetails',
        component: () => import('@/views/resume/resumeDetails'),
        meta: { title: 'resumeDetails' }
      }
    ]
  },

  // 招聘信息详情
  {
    path: '/recruitment',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/recruitment/recruitmentDetails',
        name: 'RecruitmentDetails',
        component: () => import('@/views/recruitment/recruitmentDetails'),
        meta: { title: 'recruitmentDetails' }
      }
    ]
  },

  // 新增招聘信息
  {
    path: '/recruitment',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/recruitment/recruitmentAdd',
        name: 'RecruitmentAdd',
        component: () => import('@/views/recruitment/recruitmentAdd'),
        meta: { title: 'recruitmentAdd' }
      }
    ]
  },



  // 图标
  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/icons/index'),
  //       name: 'Icons',
  //       meta: { title: 'icons', icon: 'icon', noCache: true, roles: ['admin'] }
  //     }
  //   ]
  // },

  // 企业资料
  {
    path: '/enterprise-info',
    component: Layout,
    redirect: '/enterprise-info/baseInfo',
    name: 'Enterprise-info',
    meta: {
      title: 'enterpriseinfo',
      icon: 'el-icon-office-building',
      roles: ['enterprise']
    },
    children: [
      {
        path: 'baseInfo',
        component: () => import('@/views/enterprise-info/baseInfo'),
        name: 'BaseInfo',
        meta: { title: 'baseInfo', icon: 'el-icon-house', noCache: true }
      }, {
        path: 'authentication',
        component: () => import('@/views/enterprise-info/authentication'),
        name: 'Authentication',
        meta: { title: 'authentication', icon: 'el-icon-medal', noCache: true }
      }, {
        path: 'album',
        component: () => import('@/views/enterprise-info/album'),
        name: 'Album',
        meta: { title: 'album', icon: 'el-icon-picture-outline', noCache: true }
      }
    ]
  },

  // 招聘中心
  {
    path: '/recruitment',
    component: Layout,
    children: [
      {
        path: 'recruitment',
        component: () => import('@/views/recruitment/index'),
        name: 'Recruitment',
        meta: { title: 'recruitment', icon: 'icon', noCache: true, roles: ['enterprise'] }
      }
    ]
  },

  // 账号设置
  {
    path: '/profile',
    component: Layout,
    children: [
      {
        path: 'profile',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'el-icon-s-tools', noCache: true }
      }
    ]
  },


  // 管理员审核
  {
    path: '/examine',
    component: Layout,
    redirect: '/examine/authenticationExamine',
    name: 'Examine',
    meta: {
      title: 'examine',
      icon: 'el-icon-s-check',
      roles: ['admin']
    },
    children: [
      {
        path: 'authentication',
        component: () => import('@/views/examine/authenticationExamine'),
        name: 'AuthenticationExamine',
        meta: { title: 'authenticationExamine', icon: 'el-icon-suitcase' }
      },
      {
        path: 'recruit',
        component: () => import('@/views/examine/recruitExamine'),
        name: 'RecruitExamine',
        meta: { title: 'recruitExamine', icon: 'list' }
      }
    ]
  },

  /**当路由图太长时，可以将其拆分为小模块*/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  // tableRouter,

  // 人才广场
  {
    path: '/talentSquare',
    component: Layout,
    children: [
      {
        path: 'talentSquare',
        component: () => import('@/views/talentSquare/index'),
        name: 'TalentSquare',
        meta: { title: 'talentSquare', icon: 'el-icon-s-custom', roles: ['enterprise'] }
      }
    ]
  },

  // 职场资讯
  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'Example',
    meta: {
      title: 'example',
      icon: 'el-icon-s-help',
      roles: ['admin']
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: { title: 'createArticle', icon: 'edit' }
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
        hidden: true
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: { title: 'articleList', icon: 'list' }
      }
    ]
  },


  //404页面必须放在最后
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
